'use strict';
function rank_by_two_large_one_small(collection){
  collection = collection.sort((a,b)=>(a-b)) ;
  return groupthree(collection).reduce((previousValue,value)=>{
      return previousValue.concat(twoSmallOne(value)) ;
  },[])
}

module.exports = rank_by_two_large_one_small;
//换位置
function twoSmallOne(array){//数组长度固定为3
  if(array.length !== 3){
    return array ;
  }
  array[3] =array[0] ;
  array.shift() ;
  return array ;
}
//分成三个一组
function groupthree(array){
  let result = [] ;
  let L = array.length ;
  for(let i = 0;i<L;i=i+3){
    result.push(array.slice(i,i+3));
  }
  return result ;
}
module.exports = rank_by_two_large_one_small;
